{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "233b203a-1a75-4e1f-a022-ad3523989552",
   "metadata": {},
   "source": [
    "Chapter 15\n",
    "\n",
    "# 从邻接矩阵到无向图\n",
    "《线性代数》 | 鸢尾花书：数学不难"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c0aa49d-7fbc-47e4-a4a9-c1abe77fed6f",
   "metadata": {},
   "source": [
    "这段代码从数学角度完整展示了如何用**邻接矩阵 (adjacency matrix)**来创建一个无向图，并将其可视化。我们一步步来理解每个操作的数学含义。\n",
    "\n",
    "首先，定义了一个 $4 \\times 4$ 的邻接矩阵：\n",
    "\n",
    "$$\n",
    "A = \\begin{bmatrix}\n",
    "0 & 1 & 1 & 1 \\\\\n",
    "1 & 0 & 1 & 0 \\\\\n",
    "1 & 1 & 0 & 1 \\\\\n",
    "1 & 0 & 1 & 0 \\\\\n",
    "\\end{bmatrix}\n",
    "$$\n",
    "\n",
    "这个矩阵 $A$ 是一个对称矩阵，即 $A = A^T$，因此它表示的是一个**无向图**。矩阵中第 $i$ 行第 $j$ 列的元素 $A_{ij}$ 等于 $1$，表示节点 $i$ 和节点 $j$ 之间有一条无向边；$A_{ij} = 0$ 表示两节点之间没有连接。\n",
    "\n",
    "$A$ 中每一行（或列）表示一个节点与其他节点的连接情况。例如第 0 行是 `[0, 1, 1, 1]`，说明第 0 个节点与第 1、2、3 个节点都有边相连。\n",
    "\n",
    "接着，代码使用 `networkx.Graph(adjacency_matrix)` 创建一个图对象 `undirected_G`，这个图的节点初始编号是整数 $0, 1, 2, 3$，与邻接矩阵的行列编号一致。\n",
    "\n",
    "随后通过一个映射 `mapping = {0:'a', 1:'b', 2:'c', 3:'d'}`，将节点编号重命名为更具可读性的字符 `'a', 'b', 'c', 'd'`。数学上这相当于定义了一个**节点重标记函数** $f: \\{0,1,2,3\\} \\to \\{\\text{a,b,c,d}\\}$，在图结构不变的情况下，更改节点标签。\n",
    "\n",
    "然后，代码定义了每个节点的二维坐标：\n",
    "\n",
    "$$\n",
    "\\text{pos} = \\{\n",
    "\\text{a}: (0, 0),\\;\n",
    "\\text{b}: (1, 0),\\;\n",
    "\\text{c}: (1, 1),\\;\n",
    "\\text{d}: (0, 1)\n",
    "\\}\n",
    "$$\n",
    "\n",
    "这相当于给图中每个节点指定一个平面上的坐标，用于图形可视化。你可以将这个操作看作是把抽象的图嵌入到二维欧几里得空间 $\\mathbb{R}^2$ 中。\n",
    "\n",
    "最后一步调用 `nx.draw_networkx(...)`，把图画出来。这是一个可视化函数，它根据邻接关系 $A$ 画出节点之间的连线；并根据位置 `pos` 确定每个节点的绘制位置。节点大小设置为 188，`with_labels=True` 表示将节点名称显示出来。\n",
    "\n",
    "总结来说，这段代码实现了以下数学过程：\n",
    "\n",
    "- 通过邻接矩阵 $A$ 表示一个无向图 $G$；\n",
    "- 定义了一个从整数编号到字母标签的映射；\n",
    "- 将图嵌入到 $\\mathbb{R}^2$ 中；\n",
    "- 以图形方式展现图结构。\n",
    "\n",
    "换句话说，它把一个抽象的图 $G = (V, E)$ 转换成了一个可视化对象，其中：\n",
    "\n",
    "- 顶点集合 $V = \\{\\text{a, b, c, d}\\}$，\n",
    "- 边集合 $E = \\{(\\text{a,b}), (\\text{a,c}), (\\text{a,d}), (\\text{b,c}), (\\text{c,d})\\}$。\n",
    "\n",
    "这种基于邻接矩阵的表示方法，在图论、网络分析、线性代数与组合优化等领域广泛使用。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19e5bd7e-bd17-482e-be3e-000b596a09d0",
   "metadata": {},
   "source": [
    "## 初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7d7c462a-c294-4f88-a4a7-6be0b6aecf17",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import networkx as nx\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "633d0f38-8b87-42ca-abc0-e738d80a67cc",
   "metadata": {},
   "source": [
    "## 定义邻接矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e53aa32b-f827-44a3-bba3-3927279c3615",
   "metadata": {},
   "outputs": [],
   "source": [
    "adjacency_matrix = np.array([[0, 1, 1, 1],\n",
    "                             [1, 0, 1, 0],\n",
    "                             [1, 1, 0, 1],\n",
    "                             [1, 0, 1, 0]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f0820c2-fda1-4f4b-9cbf-e520ac9fa465",
   "metadata": {},
   "source": [
    "## 创建无向图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "52fd8065-1144-4886-afe3-840e57de0ee0",
   "metadata": {},
   "outputs": [],
   "source": [
    "undirected_G = nx.Graph(adjacency_matrix, nodetype=int)\n",
    "# 用邻接矩阵创建无向图\n",
    "\n",
    "# 构造节点映射\n",
    "mapping = {0: 'a', 1: 'b', 2: 'c', 3: 'd'}\n",
    "\n",
    "# 重命名节点\n",
    "undirected_G = nx.relabel_nodes(undirected_G, mapping)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74501c72-2205-46cc-8ddb-8abe91e32e31",
   "metadata": {},
   "source": [
    "## 定义节点坐标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a62cc18d-eb71-4490-8dc0-2731ada91042",
   "metadata": {},
   "outputs": [],
   "source": [
    "pos = {'a':[0, 0], \n",
    "       'b':[1, 0],\n",
    "       'c':[1, 1],\n",
    "       'd':[0, 1]}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ba47ad7-2bd9-4660-b4af-7d395276aad1",
   "metadata": {},
   "source": [
    "## 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ced4448e-0ef3-496a-b3d5-9ed907c7c713",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeQAAAHiCAYAAAA597/kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAxGklEQVR4nO3deZzN9eLH8fcZY8syyM6ISMkSSuutOWc2jGwhUrYklVLad+K6XJdLSpKdkLLLNts5UokKESqyNAzZxsxYxpg5398fXf2SbTAzn+855/X8b845zuNdZx7zmvM933PGYVmWJQAAYFSQ6QEAAIAgAwBgCwQZAAAbIMgAANgAQQYAwAYIMgAANkCQAQCwAYIMAIANBOfkRl6vV8nJySpRooQcDkdebwIAwG9YlqX09HRVrlxZQUEXfh6coyAnJycrNDQ018YBABBokpKSVLVq1Qten6MglyhR4s87K1myZO4sAwAgAKSlpSk0NPTPll5IjoJ85jB1yZIlCTIAAFfgUi/5clIXAAA2QJABALABggwAgA0QZAAAbIAgAwBgAwQZAAAbIMgAANgAQQYAwAYIMgAANkCQAQCwAYIMAIANEGQAAGyAIAMAYAMEGQAAGyDIAADYAEEGAMAGCDIAADZAkAEAsAGCDACADRBkAABsgCADAGADBBkAABsgyAAA2ABBBgDABggyAAA2QJABALABggwAgA0Emx5wNTYnp2r++r3an5ah46eyVKxwsCqWLKK2jaqobuUQ0/MAAHnI3xrgsCzLutSN0tLSFBISotTUVJUsWTI/dl1QZpZXSzYla8rXu/TDnlQFBznktSx5LSnIIQU5HMryWrqlaoi6311dLepXVqFgDgQAgD/wxQbktKE+FeSU45l6dOq3Wp90VEEOyXuR5WeubxRaSpO6NVHpYoXybygAINf5agNy2lCfeep45Him2o79Shv3pkq6+ANxdNUM7RxyvyRp495UtR37lVKOZ+bHTABAHricBvz1el9qgE8EOTPLq55Tv1VSykllX+pR+Jtsr6WklJN6dOq3yszy5tFCAEBeCZQG+ESQl2xK1vqko5f9QJyR7bW0Pumolm7al8vLAAB5LVAa4BNnWU/5etcFXy84sf1bHf1imk4fTlKB4teqROMW572PIIc0ZfUutWlUJY/XAgBy08UacPpwko5+OUsZuzfKe+qYChQrrSKh9XRt875yBBf883a+0ADbB/nH5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CDACADRBkAABsgCADAGADBBkAABsgyAAA2ABBBgDABggyAAA2QJABALABggwAgA0QZAAAbIAgAwBgA8E5uZFlWZKktLS0PB0DAIC/OdPOMy29kBwFOT09XZIUGhp6lbMAAAhM6enpCgkJueD1DutSyZbk9XqVnJysEiVKyOFw5OpAAAD8mWVZSk9PV+XKlRUUdOFXinMUZAAAkLc4qQsAABsgyAAA2ABBBgDABggyAAA2QJABALABggwAgA0QZAAAbOD/APaTPvIQXkfzAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 600x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize = (6,6))\n",
    "nx.draw_networkx(undirected_G, pos = pos, node_size = 188, with_labels=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32a7f1da-9503-4634-ae7b-ec982967cc9b",
   "metadata": {},
   "source": [
    "## 邻接矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "52210193-96bb-4b37-b0fa-13c8dd17ecad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 1],\n",
       "       [1, 0, 1, 0],\n",
       "       [1, 1, 0, 1],\n",
       "       [1, 0, 1, 0]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = nx.adjacency_matrix(undirected_G).toarray()\n",
    "A"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72ab841b-d135-474d-9670-b8e2cd0a737d",
   "metadata": {},
   "source": [
    "作者\t**生姜DrGinger**  \n",
    "脚本\t**生姜DrGinger**  \n",
    "视频\t**崔崔CuiCui**  \n",
    "开源资源\t[**GitHub**](https://github.com/Visualize-ML)  \n",
    "平台\t[**油管**](https://www.youtube.com/@DrGinger_Jiang)\t\t\n",
    "\t\t[**iris小课堂**](https://space.bilibili.com/3546865719052873)\t\t\n",
    "\t\t[**生姜DrGinger**](https://space.bilibili.com/513194466)  "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
